package cn.zians.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Date 2020 8.28 12:17
 */
@Component
@ControllerAdvice//全局异常处理
public class NormalException {
    @ExceptionHandler(Exception.class)//异常处理器，参数为异常类型
    @ResponseBody
    public GeneralResult hanleException(Exception ex) {
        GeneralResult result = new GeneralResult();
        result.setFlag(false);
        result.setMsg(ex.getMessage());//异常信息的封装
        return result;
    }
}
